<template>
  <div class="relevance-drawing">
    <RelevanceDrawing title="关联图纸" interface-path="/slm-admin/api/v1/shopDesignPicture/getUnConnectPic" :data="drawingData" :other-filters="otherFilters" @change="changeHandle" />
    <div class="btn-container">
      <c-button type="primary" @click="clickPrevStep">上一步</c-button>
      <c-button type="primary" @click="clickNextStep">下一步</c-button>
    </div>
  </div>
</template>
<script>
import RelevanceDrawing from './components/rd'
import { otherFiltersItem } from '@/utils'
import { postInsertPic } from '@/api/decorate'
export default {
  name: 'DecorateRelevanceDrawing',
  components: {
    RelevanceDrawing
  },
  props: {
    formData: {
      type: Object,
      default: () => ({
        designPictureDTOS: []
      }),
      required: true
    },
    drawingData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
    }
  },
  computed: {
    otherFilters() {
      //  1.图纸数据展示范围：所有图纸类型为”施工图“，且图纸进度值为”已完成“的图纸；
      return [
        otherFiltersItem('picType', 'SG', '='),
        otherFiltersItem('schedule', 'F', '='),
        otherFiltersItem('isOutpicUndecoration', '0', '='),
        otherFiltersItem('constCode', this.formData.constCode, '=')
      ]
    }
  },
  methods: {
    changeHandle(v) {
      this.formData.designPictureDTOS = v || []
    },
    clickPrevStep() {
      this.$emit('prev', 0)
    },
    clickNextStep() {
      if (this.formData.designPictureDTOS.length === 0) {
        this.$message.warning('请选择图纸！')
        return
      }
      const designRange = []
      for (const p of this.formData.designPictureDTOS || []) {
        designRange.push(...this.$split(p.designRange))
      }
      if (!this.$eqSet(this.formData.range, designRange)) {
        this.$message.warning('选择的图纸范围与本次装修范围集合不一致！')
        return
      }
      let shopDecorationArea = []
      this.formData.designPictureDTOS.forEach(e => {
        const designSpace = this.$split(e.designSpace)
        shopDecorationArea.push(...designSpace)
      })
      shopDecorationArea = Array.from(new Set(shopDecorationArea))
      const data = {
        id: this.formData.id,
        designPictureDTOS: this.formData.designPictureDTOS,
        shopDecorationArea: shopDecorationArea.join(',')
      }
      return postInsertPic(data).then(res => {
        this.$message.success('保存成功！')
        this.$emit('next', 2)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.relevance-drawing{

}
</style>
